package com.dadibadi.core.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dadibadi.core.dao.entity.UserInfoTab;
import com.dadibadi.core.dao.mapper.UserInfoMapper;
import com.dadibadi.core.user.qo.UserInfoPageQO;
import com.dadibadi.core.user.vo.UserInfoListVO;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.venusoft.developer.common.exception.BizException;
import com.venusoft.developer.common.result.CommonResult;
import com.venusoft.developer.common.result.ICommonResult;
import com.venusoft.developer.common.security.IBaseUser;
import com.venusoft.developer.web.utils.UserHolder;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * TODO
 *
 * @author : lkfs@163.com
 * @date : 2025-08-26 09:37
 */

@RestController
@RequestMapping("/api")
@Slf4j
@Tag(name = "api/用户信息", description = "")
public class AdminUserMemberPageController {
    @Resource
    private UserInfoMapper userInfoMapper;

    @PostMapping("/admin-user-member-page")
    @Operation(summary = "分页查询", description = "")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", content = {@Content(schema = @Schema(implementation = UserInfoListVO.class), mediaType = "application/json")})})
    public ICommonResult exec(
            @RequestBody @Parameter(required = true) @Validated UserInfoPageQO qo,
            @RequestHeader(required = false) String platform,
            @RequestHeader(required = false) String version,
            @RequestHeader(required = false, name = "Accept-Language") String language,
            HttpServletRequest request) {

        IBaseUser<String> curUser = UserHolder.get(String.class).orElseThrow(() -> BizException.DATA_NOT_FOUND.withMessage("The user does not exists"));

        MPJLambdaWrapper<UserInfoTab> wrapper = new MPJLambdaWrapper<UserInfoTab>()
                .selectAll(UserInfoTab.class)
                .eq(UserInfoTab::getMemberFlag,1);
        IPage<UserInfoListVO> result = userInfoMapper.selectJoinPage(qo.getPage(), UserInfoListVO.class, wrapper);

        return new CommonResult<>(result);

    }
}
